﻿using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace UniversalAdmin.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class InitPermission : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MenuRole_menus_MenusId",
                table: "MenuRole");

            migrationBuilder.DropForeignKey(
                name: "FK_MenuRole_roles_RolesId",
                table: "MenuRole");

            migrationBuilder.DropIndex(
                name: "IX_roles_Name",
                table: "roles");

            migrationBuilder.RenameColumn(
                name: "RolesId",
                table: "MenuRole",
                newName: "MenuId");

            migrationBuilder.RenameColumn(
                name: "MenusId",
                table: "MenuRole",
                newName: "RoleId");

            migrationBuilder.RenameIndex(
                name: "IX_MenuRole_RolesId",
                table: "MenuRole",
                newName: "IX_MenuRole_MenuId");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "roles",
                type: "text",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "character varying(50)",
                oldMaxLength: 50);

            migrationBuilder.AddForeignKey(
                name: "FK_MenuRole_menus_MenuId",
                table: "MenuRole",
                column: "MenuId",
                principalTable: "menus",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MenuRole_roles_RoleId",
                table: "MenuRole",
                column: "RoleId",
                principalTable: "roles",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MenuRole_menus_MenuId",
                table: "MenuRole");

            migrationBuilder.DropForeignKey(
                name: "FK_MenuRole_roles_RoleId",
                table: "MenuRole");

            migrationBuilder.RenameColumn(
                name: "MenuId",
                table: "MenuRole",
                newName: "RolesId");

            migrationBuilder.RenameColumn(
                name: "RoleId",
                table: "MenuRole",
                newName: "MenusId");

            migrationBuilder.RenameIndex(
                name: "IX_MenuRole_MenuId",
                table: "MenuRole",
                newName: "IX_MenuRole_RolesId");

            migrationBuilder.AlterColumn<string>(
                name: "Name",
                table: "roles",
                type: "character varying(50)",
                maxLength: 50,
                nullable: false,
                oldClrType: typeof(string),
                oldType: "text");

            migrationBuilder.CreateIndex(
                name: "IX_roles_Name",
                table: "roles",
                column: "Name",
                unique: true);

            migrationBuilder.AddForeignKey(
                name: "FK_MenuRole_menus_MenusId",
                table: "MenuRole",
                column: "MenusId",
                principalTable: "menus",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MenuRole_roles_RolesId",
                table: "MenuRole",
                column: "RolesId",
                principalTable: "roles",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
